﻿Public Class Frm_Representant

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            Dim r As IEnumerable(Of String) = Nothing
            If Partager.type = "الممثل القانوني للموكل" Then
                r = From clt As Client In Partager.moi.List_client
                                              Select clt.Representant_legal Distinct

            ElseIf Partager.type = "الممثل القانوني للخصم" Then
                r = From clt As Enemie In Partager.moi.List_enemi
                                             Select clt.Representant_legal Distinct

            End If

            For Each av As String In r
                If av.ToString.Contains(txt_rech.Text) Then
                    Partager.list_recherch.Add(av)
                    List_tous.Items.Add(New ListViewItem(New String() {av}))
                End If
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click
        If List_tous.SelectedIndices.Count > 0 Then
            Dim j As Integer = 0
            Dim str As String = ""
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    'avo = Partager.list_recherch(i)

                    str = Partager.list_recherch(i)

                    For Each cmb As Control In Partager.frmMoule.Controls
                        If TypeOf cmb Is ComboBox Then
                            If cmb.Name = "Comb_nom" Then
                                cmb.Text = str
                                Exit For
                            End If
                        End If
                    Next
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر ممثل قانوني من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub

    Private Sub Frm_Representant_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_a7kame.Enabled = True
    End Sub
End Class